4 #define MAX(a,b) ((a>b)?(a):(b))
10 int lcs(const string
&s
, const string
&t
){
11 int m
= s
.size(), n
= t
.size();
12 if (m
== 0 || n
== 0) return 0;
13 for (int i
=0; i
<=m
; ++i
)
15 for (int j
=1; j
<=n
; ++j
)
17 for (int i
=0; i
<m
; ++i
)
18 for (int j
=0; j
<n
; ++j
)
20 dp
[i
+1][j
+1] = dp
[i
][j
]+1;
22 dp
[i
+1][j
+1] = MAX(dp
[i
+1][j
], dp
[i
][j
+1]);
34 cout
<< lcs(s
, t
) << endl
;